﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIA.Integration;

namespace VIA.SiMoJi.Domain.Electronics
{
    /// <summary>
    ///     带指示灯的按钮
    /// </summary>
    public class LightButton : EventButton, IRefreshing
    {
        private readonly IoPoint _lightIo;
        private bool _isLight;

        public LightButton(IoPoint pressedIo, IoPoint lightIo) : base(pressedIo)
        {
            _lightIo = lightIo;
        }

        public bool IsLight
        {
            get => _lightIo.Value;
            set
            {
                if (IsLight != value)
                {
                    _lightIo.Value = value;
                    _isLight = value;
                }
            }
        }

        public void Refreshing()
        {
            if (IsLight != IsPressed)
                IsLight = IsPressed;
        }

        public void Reset()
        {
            _lightIo.Value = false;
        }
    }
}
